Repository navigation
Conversation
Codecov Report❌ Patch coverage is
... and 7 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
Do you happen to have an idea about whether the speedup is mostly because of the pre-computed linear indices, or just from the chunking, i.e. reducing the overhead? I recently attempted to make the Strided calls a lot less overhead, especially for small tensors, so I'm hoping that just the chunking could suffice. See also the work in #584, where I also introduced some chunking (there the main motivation was multithreading, since for many small blocks the contention on the single atomic Int is quite large). |
|
I tried to disentangle the two by running the different steps separately on the same transformer data (Strided 2.6.6, so including your recent changes;
It turns out that both matter, but most of the time saved comes from avoiding the per-call overhead. For the five tensors with subblocks of at most 16 entries (two of which are shown above), a single Strided call still costs 440–570 ns, and simply replacing it by a plain loop over each subblock already makes things 3–7× faster. Grouping the subblocks by shape doesn't do much by itself, but it's precisely what makes the precomputed index lists cheap, since we only need one list per shape. Those index lists then give another 2.5–12×. Once the subblocks reach 256 entries, all of the hand-written loops perform about the same. A second run gave the same picture. I haven't tried QuantumKitHub/Strided.jl#84 here. I also ran #584 next to main and this PR on the four fℤ₂ × U(1) tensors from the description (
The node was still busy, so these are noisier than the numbers above, but #584 stays within 2× of main here, since it still calls |
…ensoradd! per subblock Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hold Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test suite runs with one transformer task, so the path that splits the groups over tasks by destination offset was not covered. Compare `permute` and `permute!` with β ≠ 0 using three tasks against the serial result, for a fermionic U(1) tensor (unique fusion) and an SU(2) tensor with subblocks on both sides of the group threshold (generic fusion, accumulating groups). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and trim their other vectors to length Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ed76496 to
b92a58b
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # src/tensors/treetransformers.jl
On the CPU,
permute,braidandtransposecalltensoradd!once per fusion-tree subblock, which costs about 0.5–0.7 µs per call independent of the subblock size. For tensors with many small subblocks, such as fermionic U(1)-symmetric PEPS tensors, this dominates:permute!becomes 25–125× slower than copying the data. This is the same per-subblock pattern as #595, and the CPU counterpart of #508.This PR collects the subblocks with at most 1024 entries into groups of equal size and strides when the tree transformer is built, and caches them with it: per group the relative positions of the entries in the destination and the permuted source, per subblock the offsets and the coefficient.
add_transform_kernel!then transforms every group in a single loop, while larger subblocks still go throughtensoradd!one by one. For sectors with multiple fusion channels, the recoupling of small subblocks is applied term by term in the same loops instead of through pack,mul!and unpack. With multiple transformer threads, the tasks handle disjoint ranges of destination offsets.permute!into a preallocated destination, one thread, best of 30, in ms (p1 = ((1, 4, 2), (5, 3, 6))onVχ ⊗ VD ⊗ VD' ← Vχ ⊗ VD ⊗ VD'):copy!Vχcharges ±2, deg. 4;VD±1, deg. 1Vχcharges ±8, deg. 2;VD±1, deg. 1Vχcharges ±2, deg. 16;VD±1, deg. 1Vχcharges ±2, deg. 32;VD±1, deg. 2Vχj ≤ 1, deg. 2;VDj ≤ 1/2, deg. 1Vχj ≤ 1, deg. 16;VDj ≤ 1/2, deg. 2Tensors whose subblocks are all larger than 1024 entries take the same path as before. The existing permutation tests only have subblocks of up to 12 entries, so I added one testset with subblocks on both sides of the threshold.
The offsets of the groups are stored as
Int32(tensors with more thantypemax(Int32)entries are not grouped), and the relative positions of a subblock shape are cached and shared between all transformers. In one gradient of a D = 8 fermionic SU(2) PEPS (FermionParity ⊠ U1Irrep ⊠ SU2Irrep), the groups then take about 3.2 GiB (offsets 1.51, coefficients 1.51, relative positions 0.16 GiB), against 6.6 GiB withIntoffsets and positions of their own; warm gradients took the same time withInt32offsets (median of 15: 108 s against 106 s, single gradients 89–123 s). For all 480 permutations of a small tensor of the same kind (second reproducer below), TensorKit's caches hold 89.5 MiB on main, 119.8 MiB with the groups asIntwith their own positions, and 100.8 MiB with these two changes, while the same permutations with full caches take 0.013 s against 0.152 s on main. Building the transformers from empty caches took longer in these runs: 1.58 s on main, 2.19 s with the groups and 3.28 s with these changes (single runs on the same machine, not side by side). The GPU extension builds the groups as well but does not use them. The table above was measured before these two changes.Reproducer
main:
this PR:
Reproducer for the cache size
main:
this PR:
🤖 Generated with Claude Code